<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册 - 养老院管理系统</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
    <link rel="stylesheet" th:href="@{/css/main.css}">
</head>
<body>
<div class="auth-wrapper">
    <div class="auth-card">
        <div class="card-header">
            <h4 class="text-primary">养老院管理系统</h4>
            <h5>注册新账号</h5>
        </div>
        <div class="card-body">
            <div th:if="${param.success}" class="alert alert-success">
                注册成功！请<a th:href="@{/login}">登录</a>。
            </div>
            <form th:action="@{/register}" method="post" class="needs-validation" novalidate>
                <div class="form-group">
                    <label for="username">用户名</label>
                    <input type="text" class="form-control" id="username" name="username" required>
                    <div class="invalid-feedback">
                        请输入用户名
                    </div>
                </div>
                <div class="form-group">
                    <label for="email">电子邮箱</label>
                    <input type="email" class="form-control" id="email" name="email" required>
                    <div class="invalid-feedback">
                        请输入有效的电子邮箱地址
                    </div>
                </div>
                <div class="form-group">
                    <label for="password">密码</label>
                    <input type="password" class="form-control" id="password" name="password" required minlength="6">
                    <div class="invalid-feedback">
                        密码长度至少为6个字符
                    </div>
                </div>
                <div class="form-group">
                    <label for="confirmPassword">确认密码</label>
                    <input type="password" class="form-control" id="confirmPassword" name="confirmPassword" required>
                    <div class="invalid-feedback">
                        两次输入的密码不一致
                    </div>
                </div>
                <div class="form-group">
                    <label for="fullName">姓名</label>
                    <input type="text" class="form-control" id="fullName" name="fullName" required>
                    <div class="invalid-feedback">
                        请输入您的姓名
                    </div>
                </div>
                <div class="form-group">
                    <label for="phone">手机号码</label>
                    <input type="tel" class="form-control" id="phone" name="phone" required pattern="[0-9]{11}">
                    <div class="invalid-feedback">
                        请输入有效的11位手机号码
                    </div>
                </div>
                <button type="submit" class="btn btn-primary btn-block">注册</button>
            </form>
            <div class="text-center mt-3">
                <a th:href="@{/login}" class="text-decoration-none">已有账号？登录</a>
            </div>
        </div>
        <div class="card-footer text-center text-muted">
            <small>&copy; 2023 养老院管理系统</small>
        </div>
    </div>
</div>

<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.bundle.min.js"></script>
<script th:src="@{/js/main.js}"></script>
<script>
    // 密码确认验证
    document.getElementById('confirmPassword').addEventListener('input', function() {
        const password = document.getElementById('password').value;
        const confirmPassword = this.value;

        if (password !== confirmPassword) {
            this.setCustomValidity('两次输入的密码不一致');
        } else {
            this.setCustomValidity('');
        }
    });
</script>
</body>
</html>